package com.ruoyi.web.controller.jiaxiao;

import java.math.BigDecimal;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.JxPayment;
import com.ruoyi.system.service.IJxPaymentService;

@RestController
@RequestMapping("/jiaxiao/payment")
public class JxPaymentController extends BaseController {

    @Autowired
    private IJxPaymentService service;

    @PreAuthorize("@ss.hasPermi('jiaxiao:payment:list')")
    @GetMapping("/list")
    public TableDataInfo list(JxPayment query) {
        startPage();
        List<JxPayment> list = service.selectList(query);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('jiaxiao:payment:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable Long id) { return AjaxResult.success(service.selectById(id)); }

    @PreAuthorize("@ss.hasPermi('jiaxiao:payment:add')")
    @Log(title = "缴费", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JxPayment e) { return toAjax(service.insert(e)); }

    @PreAuthorize("@ss.hasPermi('jiaxiao:payment:edit')")
    @Log(title = "缴费", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JxPayment e) { return toAjax(service.update(e)); }

    @PreAuthorize("@ss.hasPermi('jiaxiao:payment:remove')")
    @Log(title = "缴费", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) { return toAjax(service.deleteByIds(ids)); }

    @PreAuthorize("@ss.hasPermi('jiaxiao:payment:query')")
    @GetMapping("/sumPaid/{studentId}")
    public AjaxResult sumPaid(@PathVariable Long studentId) { BigDecimal amt = service.sumPaidByStudent(studentId); return AjaxResult.success(amt); }
}


